//-------------------------------------------------------------------
//	Copyright (c) 2010-2012 Zhirnov Andrey
//	This file is part of the "UXGEN" project.
//	See copyright notice in "Engine.h".
//-------------------------------------------------------------------

#ifndef _UX_RTPASS_BUILTIN_H
#define _UX_RTPASS_BUILTIN_H

#include "IRTPass.h"
#include "TRTMessage.h"

namespace Engine
{
namespace RenderUtils
{

	//
	// Draw Render Queue Built-in Pass (Deferred Rendering)
	//
	
	class CDRBuiltinDrawRenderQueue : public IRTPass
	{
	protected:
		TCameraRenderQueue	**	_pQueue;
		union {
			ivec4			*	_pIteration;
			uint				_uLayer;
		};
		
	protected:
		static void _s_DrawLayer(void *);
		static void _s_DrawIterationLayers(void *);

	public:
		CDRBuiltinDrawRenderQueue(IRTPass *pParent);
		~CDRBuiltinDrawRenderQueue();

		bool Create(uint uLayer = -1);
		
		virtual bool ProcessMessage(TRTMessage &sMsg);

		virtual EPassType GetPassType() const		{ return BUILT_IN; }
	};



	//
	// Draw Render Queue with box occlusion culling Built-in Pass
	//
	
	class CBuiltinDrawRenderQueueOC : public CDRBuiltinDrawRenderQueue
	{
	protected:
		CQueryObject	*	_pQuery;
		CShaderProgramPtr	_pShader;
		uint8				_uVPMatLoc,
							_uAABBLoc;
		
	protected:
		static void _s_DrawLayerOC(void *);
		static void _s_DrawIterationLayersOC(void *);

	public:
		CBuiltinDrawRenderQueueOC(IRTPass *pParent);
		~CBuiltinDrawRenderQueueOC();

		bool Create(const CShaderProgramPtr &pShader, uint uLayer = -1);
		
		virtual bool ProcessMessage(TRTMessage &sMsg);

		virtual EPassType GetPassType() const		{ return BUILT_IN; }
	};



	//
	// Draw Render Queue Built-in Pass (Forward Rendering)
	//
	
	/*class CFRBuiltinDrawRenderQueue : public IRTPass
	{
	protected:
		TCameraRenderQueue	**	_pQueue;
		union {
			ivec4			*	_pIteration;
			uint				_uLayer;
		};
		
	protected:
		static void _s_DrawLayer(void *);
		static void _s_DrawIterationLayers(void *);

	public:
		CFRBuiltinDrawRenderQueue(IRTPass *pParent);
		~CFRBuiltinDrawRenderQueue();

		bool Create(uint uLayer = -1);
		
		virtual bool ProcessMessage(TRTMessage &sMsg);

		virtual EPassType GetPassType() const		{ return BUILT_IN; }
	};
*/



	//
	// Setup Shadow Built-in Pass
	//

	class CBuiltinSetupShadow : public IRTPass
	{
	protected:
		IRTPass		*	_pDrawRenderQueue;
		e_light::type	_eLight;
		e_shadow::type	_eShadow;
		vec2			_vRange;

	public:
		CBuiltinSetupShadow(IRTPass *pParent);
		~CBuiltinSetupShadow();

		bool Create(IRTPass *, e_light::type, e_shadow::type, const vec2 &);
		
		virtual bool ProcessMessage(TRTMessage &sMsg);

		virtual EPassType GetPassType() const		{ return BUILT_IN; }
	};



	//
	// Setup Light Built-in Pass
	//

	class CBuiltinSetupLight : public IRTPass
	{
	protected:
		CBaseProgramShellPtr	_pProgram;
		e_light::type			_eLight;
		e_shadow::type			_eShadow;

	public:
		CBuiltinSetupLight(IRTPass *pParent);
		~CBuiltinSetupLight();

		bool Create(const CBaseProgramShellPtr &, e_light::type, e_shadow::type);

		virtual bool ProcessMessage(TRTMessage &sMsg);

		virtual EPassType GetPassType() const		{ return BUILT_IN; }
	};



	//
	// Draw Lights Built-in Pass
	//

	class CBuiltinDrawLights : public IRTPass
	{
	protected:
		IRTPass		*	_pBindTextures;
		CTexturePtr		_pShadow;
		e_light::type	_eLight;

	public:
		CBuiltinDrawLights(IRTPass *pParent);
		~CBuiltinDrawLights();

		bool Create(IRTPass *, const CTexturePtr &, e_light::type);

		virtual bool ProcessMessage(TRTMessage &sMsg);

		virtual EPassType GetPassType() const		{ return BUILT_IN; }
	};



	//
	// Set Camera
	//

	class CBuiltinSetCamera : public IRTPass
	{
	protected:
		typedef TCameraRenderQueue::camera_rq_array_t	camera_rq_array_t;
		
		camera_rq_array_t	*	_pCameras;
		TCameraRenderQueue	*	_pCurrentCameraRQ;
		union {
			ivec4			*	_pIteration;
			uint				_uIndex;
		};
		
	protected:
		static void _s_SetIteration(void *);
		static void _s_SetIndex(void *);

	public:
		CBuiltinSetCamera(IRTPass *pParent);
		~CBuiltinSetCamera();

		bool Create(e_camera::type eCamType, uint uIndex);

		virtual bool ProcessMessage(TRTMessage &sMsg);

		virtual EPassType GetPassType() const		{ return BUILT_IN; }
	};



	//
	// Use User PostProcess
	//

	class CBuiltinUseUserPostProcess : public IRTPass
	{
	protected:
		IPostProcessPtr *	_pPostProcess;
		uint				_uIndex;
		
	protected:
		static void _s_UsePostProcess(void *);

	public:
		CBuiltinUseUserPostProcess(IRTPass *pParent);
		~CBuiltinUseUserPostProcess();
		
		bool Create(uint uIndex);

		virtual bool ProcessMessage(TRTMessage &sMsg);

		virtual EPassType GetPassType() const		{ return BUILT_IN; }
	};



	//
	// Draw Fullscreen Quad
	//

	class CBuiltinDrawFullscreenQuad : public IRTPass
	{
	protected:
		CBaseProgramShellPtr	_pProgram;
		bool					_bFlipY;
		
	protected:
		static void _s_Draw(void *);

	public:
		CBuiltinDrawFullscreenQuad(IRTPass *pParent);
		~CBuiltinDrawFullscreenQuad();
		
		bool Create(const CBaseProgramShellPtr &pProgram, bool bFlipY);

		virtual bool ProcessMessage(TRTMessage &sMsg);

		virtual EPassType GetPassType() const		{ return BUILT_IN; }
	};



	//
	// Profiler Begin
	//

	class CBuiltinProfilerBegin : public IRTPass
	{
	protected:
		string		_sName;
		uint		_uIndex;
		
	protected:
		static void _s_Begin(void *);

	public:
		CBuiltinProfilerBegin(IRTPass *pParent);
		~CBuiltinProfilerBegin();

		bool Create(const char *pName);

		virtual bool ProcessMessage(TRTMessage &sMsg);

		virtual EPassType GetPassType() const		{ return BUILT_IN; }
	};



	//
	// Profiler End
	//

	class CBuiltinProfilerEnd : public IRTPass
	{
	protected:
		uint	*	_pIndex;

	protected:
		static void _s_End(void *);

	public:
		CBuiltinProfilerEnd(IRTPass *pParent);
		~CBuiltinProfilerEnd();

		bool Create(const string &sName);
		
		virtual bool ProcessMessage(TRTMessage &sMsg);

		virtual EPassType GetPassType() const		{ return BUILT_IN; }
	};



	//
	// Clear Buffer
	//

	class CBuiltinClearBuffer : public IRTPass
	{
	protected:
		uint		_uIndex;
		union {
			float	_aColor[4];
			float	_fDepth;
			int		_iStencil;
		};

	protected:
		static void _s_ClearColor(void *);
		static void _s_ClearDepth(void *);
		static void _s_ClearStencil(void *);
		static void _s_ClearAll(void *);

	public:
		CBuiltinClearBuffer(IRTPass *pParent);
		~CBuiltinClearBuffer();

		bool Create(const color4f &sColor, e_fbo_attach::type eBuffer);
		bool Create(const float fValue, e_fbo_attach::type eBuffer);
		bool Create(const int iValue, e_fbo_attach::type eBuffer);
		
		virtual bool ProcessMessage(TRTMessage &sMsg);

		virtual EPassType GetPassType() const		{ return BUILT_IN; }
	};

//-------------------------------------------------------------------

}	// RenderUtils
}	// Engine

#endif	// _UX_RTPASS_BUILDIN_H